package game.farming.model;

import game.farming.ui.Player;
import java.util.Vector;

public abstract class FarmersFate{
	private String message;
	
	public FarmersFate(String message){
		this.message = message;
	}
	
	public abstract void performAction(Player p, Table t);
	
	public String getMessage(){
		return message;
	}
	
	public void setMessage(String message){
		this.message = message;
	}
	
	public static FarmersFate FF_MARKET_JUMPED = new FarmersFate("Held some of your calves and the market jumped.\nCollect $2,000 if you have cows."){
		public void performAction(Player p, Table t){
			if(p.hasProduct(Product.COWS)){
				p.addCash(2000);
			}
		}
	};
	public static FarmersFate FF_CUSTOM_BILL_1 = new FarmersFate("Custom hire bill due.\nIf you don't have a tractor\npay $3,000."){
		public void performAction(Player p, Table t){
			if(!p.hasProduct(Product.TRACTOR)){
				p.addCash(-3000);
			}
		}
	};
	public static FarmersFate FF_OIL_COMPANY = new FarmersFate("Oil company pays you\n$100 per acre for\nOil and Gas Lease on your farm."){
		public void performAction(Player p, Table t){
			int acres = 0;
			acres += p.getProductCount(Product.HAY);
			acres += p.getProductCount(Product.GRAIN);
			acres += p.getProductCount(Product.FRUIT);
			p.addCash(100 * acres);
		}
	};
	public static FarmersFate FF_ELECTRICAL_LEAK = new FarmersFate("A leaking electrical motor at the Feed Mill\ncontaminates your load of feed with PCB.\nState Ag. Inspector requires you to slaughter cows on your farm\n(not on ranches) with no reimbursement."){
		public void performAction(Player p, Table t){
			if(p.hasProduct(Product.COWS)){
				int save = 0;
				save += p.hasProduct(Product.R1) ? 20 : 0;
				save += p.hasProduct(Product.R2) ? 30 : 0;
				save += p.hasProduct(Product.R3) ? 40 : 0;
				save += p.hasProduct(Product.R4) ? 50 : 0;
				Vector<Product> products = p.getProducts();
				int count = p.getProductCount(Product.COWS);
				for(int i = products.size() - 1; i >= 0 && count > save; i--){
					if(products.get(i).equals(Product.COWS)){
						products.remove(i);
						count--;
					}
				}
			}
		}
	};
	public static FarmersFate FF_FRUIT_WORMS = new FarmersFate("Cut worms eat sprouting fruit buds.\nEPA bans the control spray.\nPay $300 per fruit acre."){
		public void performAction(Player p, Table t){
			p.addCash(-300 * p.getProductCount(Product.FRUIT));
		}
	};
	public static FarmersFate FF_RAISE_PRIME = new FarmersFate("Bank raises prime rate.\nPay 10% on outstanding loan\nas additional interest."){
		public void performAction(Player p, Table t){
			p.addCash((int) Math.round(-0.10 * p.getLoan()));
		}
	};
	public static FarmersFate FF_DROUGHT_YEAR = new FarmersFate("Drought year.\nGo to second week of January.\nDo not collect $5,000."){
		public void performAction(Player p, Table t){
			//FIXME p.moveTo( 2 );
		}
	};
	public static FarmersFate FF_MAGGOT_FLY = new FarmersFate("The apple Maggot Fly, cousin of the dreaded Medfly,\nis found in an insect trap in your orchard.\nYour orchard is quaranteened\nand you lose lucrative export contract.\nPay $500 per fruit acre."){
		public void performAction(Player p, Table t){
			p.addCash(-500 * p.getProductCount(Product.FRUIT));
		}
	};
	public static FarmersFate FF_MT_ST_HELENS = new FarmersFate("Natural disaster- Mt. St. Helens blows.\nYou were lickily out of the Ash Path\nYour ash free hay jumps in price.\nCollect $500 per hay acre.\nOther players must roll a die to see if they escaped.\nOdd - escaped; Even - hit.\nAsh hit players must pay $100 per acre to clean up mess."){
		public void performAction(Player p, Table t){
			//FIXME
		}
	};
	public static FarmersFate FF_INCOME_TAX = new FarmersFate("Income taxes due.\nPay $7,000."){
		public void performAction(Player p, Table t){
			p.addCash(-7000);
		}
	};
	public static FarmersFate FF_RUSSIAN_SALE = new FarmersFate("Russian sale boosts whear prices.\nCollect $2,000."){
		public void performAction(Player p, Table t){
			p.addCash(2000);
		}
	};
	public static FarmersFate FF_CUSTOM_BILL_2 = new FarmersFate("Custom hire out with your harvester.\nIf you have a harvester,\ncollect $2,000 from each player who has none."){
		public void performAction(Player p, Table t){
			if(p.hasProduct(Product.HARVESTOR)){
				p.addCash(2000);
			}
		}
	};
	public static FarmersFate FF_IRS = new FarmersFate("IRS garnishes your income after finding errors on your tax return.\nFor the rest of the year draw\nOperating Expense cards during harvest\nbut do not roll for harvest cheque."){
		public void performAction(Player p, Table t){
			//FIXME
		}
	};
	public static FarmersFate FF_WINDY_SPRING = new FarmersFate("Windy spring, don't get your wheat sprayed.\nWeeds cut your wheat crop in half for the year."){
		public void performAction(Player p, Table t){
			Double yield = p.getYields().get(Product.GRAIN);
			yield /= 2;
			p.getYields().put(Product.GRAIN, yield);
		}
	};
	public static FarmersFate FF_GOVT_SAVE = new FarmersFate("Federal Crop Disaster payment saves your bacon.\nCollect $100 per grain acre."){
		public void performAction(Player p, Table t){
			p.addCash(100 * p.getProductCount(Product.GRAIN));
		}
	};
	public static FarmersFate FF_UNCLE_BERT = new FarmersFate("Uncle Bert dies and leaves you\n10 acres of hay if you have $10,000 cash to pay\ninheritance tax and small remaining mortgage."){
		public void performAction(Player p, Table t){
			//FIXME
		}
	};
	public static FarmersFate FF_GRAIN_EMBARGO = new FarmersFate("The Prsident slaps on a grain embargo\nwhile you're waiting for the custom harvester to show up.\nInstant market collapse.\nPay $2,500 if you do not own a harvester."){
		public void performAction(Player p, Table t){
			if(!p.hasProduct(Product.HARVESTOR)){
				p.addCash(-2500);
			}
		}
	};
	public static FarmersFate FF_COOP_HOLDS = new FarmersFate("Marketing co-op holds out for higher price.\nProfessor gives in.\nCollect $1,000."){
		public void performAction(Player p, Table t){
			p.addCash(1000);
		}
	};
	public static FarmersFate FF_TRUCKER_STRIKE = new FarmersFate("Truckers strike delays fruit in transport.\nLots of spoilage.\nPay $1,000 per fruit acre."){
		public void performAction(Player p, Table t){
			p.addCash(-1000 * p.getProductCount(Product.FRUIT));
		}
	};
}
